<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：单据作废-->
<div th:fragment="pzcurmainInvalid" class="modal inmodal fade" id="pzcurmainInvalid_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="pzcurmainInvalid_modalTitle">单据作废</h4>
                <p id="pzcurmainInvalid_modalDesc" class="font-bold text-danger">此单据已关联审批表，作废后，可在"待我报销"中重新生成报销单</p>
            </div>
            <div class="modal-body">
                <form id="pzcurmainInvalid_Form">
                    <input id="pzcurmainInvalid_mainId" name="mainId" type="hidden"/>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="form-group">
                                <textarea id="pzcurmainInvalid_invalidRemark" name="invalidRemark" rows="2" class="form-control"
                                          placeholder="请输入作废原因" value=""></textarea>
                            </div>
                        </div>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="pzcurmainInvalidObj.submitHandler()">
                    保存
                </button>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(function () {
            $('#pzcurmainInvalid_Form').validate({
                rules: pzcurmainInvalidObj.dataRule,
                submitHandler: function (form) {
                    pzcurmainInvalidObj.dataFormSubmit(form);
                }
            });
        })
        var pzcurmainInvalidObj = new Object({
            dataRule: {
                invalidRemark: {
                    required: true,
                    maxlength: 200
                }
            },
            init: function (mainId, isExistApply) {
                $('#pzcurmainInvalid_mainId').val(mainId);
                if(isExistApply){
                    $('#pzcurmainInvalid_modalDesc').show();
                }else{
                    $('#pzcurmainInvalid_modalDesc').hide();
                }
            },
            submitHandler: function () {
                $("#pzcurmainInvalid_Form").submit();
            },
            dataFormSubmit: function (form) {
                $.mySwalConfirm(`将作废单据，确认吗？`, function () {
                    let formVals = $(form).serializeArray();
                    let data = {}
                    for (let i = 0; i < formVals.length; i++) {
                        data[formVals[i].name] = formVals[i].value;
                    }
                    $.myPost({
                        url: `/portal/process/instance/saveInvalid.json`,
                        data: data,
                        success: function (data) {
                            if (data && data.success) {
                                toastr.success(data.msg, '操作提示')
                                $('#pzcurmainInvalid_Modal').modal('hide')
                                pzcurmainListObj.refreshDataList();
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                });
            }
        })
    </script>
</div>
</body>
</html>